/**
 * 学生模块管理初始化
 */
var Student = {
    id: "studentTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Student.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '真实姓名', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: '性别', field: 'sexName', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '年龄', field: 'age', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '手机号', field: 'mobile', visible: true, align: 'center', valign: 'middle'},
            {title: '账号', field: 'username', visible: true, align: 'center', valign: 'middle'},
            {title: '家庭地址', field: 'address', visible: true, align: 'center', valign: 'middle'},
            {title: '曾用名', field: 'prename', visible: true, align: 'center', valign: 'middle'},
            {title: '籍贯', field: 'nativePlace', visible: true, align: 'center', valign: 'middle'},
            {title: '户口所在地', field: 'domicilePlace', visible: true, align: 'center', valign: 'middle'},
            {title: '出生地', field: 'birthPlace', visible: true, align: 'center', valign: 'middle'},
            {title: '出生日期（年-月-日）', field: 'birthDay', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '创建日期', field: 'createTime', visible: true, align: 'center', valign: 'middle',sortable : true},
            ];
};

/**
 * 检查是否选中
 */
Student.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Student.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加学生模块
 */
Student.openAddStudent = function () {
    var index = layer.open({
        type: 2,
        title: '添加学生模块',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/student/student_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看学生模块详情
 */
Student.openStudentDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '学生模块详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/student/student_update/' + Student.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除学生模块
 */
Student.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/student/delete", function (data) {
            Feng.success("删除成功!");
            Student.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("studentId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询学生模块参数对象
 */
Student.formParams = function () {
    var queryData = {};
    
    queryData['name'] = $("#name").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    
    return queryData;
};


/**
 * 查询学生列表
 */
Student.search = function(){
	Student.table.refresh({query: Student.formParams()});
}

/**
 * 搜索重置
 */
Student.resetSearch = function(){
	$("#name").val("");
	$("#beginTime").val("");
	$("#endTime").val("");
	
	Student.search();
}
$(function () {
    var defaultColunms = Student.initColumn();
    var table = new BSTable(Student.id, "/student/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Student.formParams());
    Student.table = table.init();
});
